package com.soft.bams.dao;

import com.soft.bams.entity.Account;

import java.util.Calendar;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/23
 */
public interface IDao<T , K> {

    //插入元素
    public boolean insert(T t);

    //根据ID和密码查询
    public T selectOne(Long id , String password);

    //根据ID查询
    public T selectOne(Long id);

    //查询所有银行账户
    public K selectAll();

    //获取ID
    public Long getId();

    //设置ID
    public void setId(Long id);

    public default Long createId(){

        String idStr = getId().toString();

        int year = Integer.parseInt(idStr.substring(8, 12));

        int month = Integer.parseInt(idStr.substring(12, 14));

        String count = idStr.substring(14);

        Calendar c = Calendar.getInstance();
        int nowYear = c.get(Calendar.YEAR);
        int nowMonth = c.get(Calendar.MONTH)+1;
        if(year!=nowYear&&month!=nowMonth){
            year = nowYear;
            month = nowMonth;
            count = "0001";
        }

        if(count.equals("9999")){
            count = "0001";
            System.out.println("您好，本月开卡名额已用完，请下个月再来！");
            return -1L;
        }

        String str = "";
        if(month<10){
            str = "86215021"+year+"0"+month+count;
        }else{
            str = "86215021"+year+month+count;
        }

        Long id = Long.valueOf(str);
        this.setId(id+1);
        return id;
    }

    public boolean update(Account updatedAccount);
}
